package com.minidemotouch;
 
import mobilefeel.sdk.MobileFeelActivity;
import android.content.Context;
import android.os.Bundle;
import android.os.PowerManager;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;

public class MiniDemoActivity extends MobileFeelActivity {
	
	private PowerManager.WakeLock wakeLock;

	@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.minidemo);
        
        PowerManager powerManager= (PowerManager) getSystemService(Context.POWER_SERVICE);
        wakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "Tesis");
        wakeLock.acquire(); 
	}
	
	@Override
	public void onWindowFocusChanged(boolean hasFocus) {
		super.onWindowFocusChanged(hasFocus);
		if (hasFocus)
			this.registerView(R.id.mainView, "Pizarra");
	}
	
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
	    MenuInflater inflater = getMenuInflater();
	    inflater.inflate(R.menu.menu, menu);
	    return true;
	}
	

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
	    switch (item.getItemId()) {
	    case R.id.desconectar:
	        disconnect();
	        finish();
	    	return true;
	    case R.id.borrar:
	    	sendCustomData("menu", "borrar");
	    	return true;
	    default:
	        return super.onOptionsItemSelected(item);
	    }
	}
	
	@Override
    protected void onResume() {
        super.onResume();
        wakeLock.acquire();
	}

	@Override
    protected void onPause() {
        super.onPause();
        wakeLock.release();
    }	

	@Override
	protected void onDestroy() {
		super.onDestroy(false);
		wakeLock.release();
	}

	@Override
	public void onBackPressed() {
		disconnect();
		super.onBackPressed();
	}

	@Override
	protected void onDisconnection(boolean remote) {
		Toast.makeText(this, "Desconectado", Toast.LENGTH_SHORT).show();
	}
	
	
}